home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Prefs / ModeProPrefs.c < prev    next >
C/C++ Source or Header  |  2000-09-17  |  24KB  |  786 lines

  1. #define DEBUG_DELAY 50
  2. //#define DEBUG
  3. #include <debug.h>
  4. #include <extras/macros/intuition.h>
  5.  
  6. #include "MPP.h"
  7. #include "mppexterns.h"
  8. #include "palettereq.h"
  9. #include <ctype.h>
  10. #include <utility/hooks.h>
  11.  
  12. //#include <clib/extras/palettereq_protos.h>
  13. //#include <extras/palettereq.h>
  14.  
  15. long __stack = 10240;
  16.  
  17. extern LONG FillShinePen,FillShadowPen;
  18. extern struct LG_Control *GadControl;
  19.  
  20. BOOL MyScreen;
  21.  
  22. LONG MsgsOut=0;
  23.  
  24. struct MPMessage *ForcedEditMsg;
  25. UBYTE  ForcedSig;
  26.  
  27. extern UBYTE   Version[];
  28. extern UBYTE   ModePro[];
  29. extern LONG SemVersion,
  30.             SemRevision;
  31.  
  32. ULONG  Arg_Promo, Arg_NLM, Arg_Ask, Arg_CH, Arg_CV, Arg_Debug, Arg_Import;
  33.  
  34.  
  35. UBYTE   AboutText[]="ModePro\n"
  36.                      "©1994-1998 by Michael Rivers\n"
  37.                      "  DonationWare (see Docs)\n\n"
  38.                      "%s\n"
  39.                      "%s\n"
  40.                      "  E-Mail:\n"
  41.                      "    mrivers@gte.net\n"
  42.                      "  WWW:\n"
  43.                      "    http://home1.gte.net/mrivers/\n"
  44.                      "  Mail:\n"
  45.                      "    Michael Rivers\n"
  46.                      "    4302 Wisconsin Court\n"
  47.                      "    Tampa, FL, USA, 33616";
  48.  
  49.  
  50. UBYTE EnvFile[]   ="ENV:ModePro.pref",
  51.       EnvArcFile[]="ENVARC:ModePro.pref";
  52.  
  53. ULONG ActivateStrGad=0;
  54. struct List PenList;
  55. LONG ActivePen=0;
  56. extern UBYTE PenNameGad[];
  57. struct PenNode pennode[DRIPENS];
  58. UWORD NumDriPens;
  59. UWORD defaultpens[]=
  60. {
  61.   0,1,1,2,1,3,1,0,2,1,2,1
  62. };
  63. float XScale=1.0,
  64.       YScale=1.0,
  65.       PXScale,
  66.       PYScale;
  67. extern STRPTR MiscText[];
  68. extern struct Hook StrHook,PenLVHook,StrCursorHook,PromotionLVHook;
  69.  
  70. extern struct NewGadget nglist[];
  71. extern ULONG gtype[];
  72. extern ULONG gtags[];
  73. extern struct BevelBox BBox[];
  74. extern UBYTE PenNames[DRIPENS][32];
  75. extern UWORD PenNumbers[];
  76. extern struct GUI_String GText[];
  77. extern WORD PenNameLength[],
  78.             BevelBoxes;
  79. struct TextAttr *TAttr, User, SysFont;
  80. struct Menu *MenuStrip;
  81. extern struct   NewMenu nm[];      
  82. struct TextAttr Topaz8 = { "topaz.font",8,0,0};
  83.  
  84. WORD LeftEdge,TopEdge; 
  85.  
  86. struct FontRequester *FontReq=0;
  87. struct FileRequester *FileReq=0;
  88. struct FileRequester *PalFileReq=0;
  89. struct ScreenModeRequester *ScrReq=0;
  90. struct FileRequester *BackdropFileReq=0;
  91. struct PaletteRequest *PalettePReq=0,*BackdropPReq=0;
  92.  
  93. APTR VI=0;
  94. struct Gadget   *glist=0;
  95. struct Screen   *Scr=0;
  96. struct Window   *Win=0;
  97. struct DrawInfo *DrawInfo;
  98.  
  99. LONG BackdropPen;
  100.  
  101. BOOL    V39;
  102.  
  103. UBYTE   filename[513];
  104.  
  105. LONG   LVActive=0,NodeCnt=0;
  106.  
  107. ULONG  ArgEdit,ArgUse,ArgSave;
  108. STRPTR ArgFrom,ArgPubscreen;
  109. UBYTE  *UserFontName;
  110. LONG   UserFontSize;
  111.  
  112. UBYTE *WindowName,
  113.       *WinAdd,
  114.       *Title1=" = <",
  115.       *Title2=">";
  116.  
  117. struct Catalog *Catalog;
  118.  
  119. BOOL ClosePrefs=FALSE;
  120. struct MPSem   *MPSem;
  121. struct MsgPort *PrefsPort,*ReplyPort;
  122.  
  123. struct IntuitionBase *IntuitionBase; 
  124. struct LocaleBase    *LocaleBase;
  125. struct GfxBase       *GfxBase;
  126. struct Library       *AslBase,
  127.                      *CxBase,
  128.                      *DiskfontBase,
  129.                      *GadToolsBase,
  130.                      *IconBase,
  131.                      *IFFParseBase,
  132.                      *UtilityBase;
  133.  
  134. struct Libs MP_Libs[]=
  135. {
  136.   (APTR *)&AslBase,      "asl.library",        36,0,
  137.   (APTR *)&CxBase,       "commodities.library",36,0,
  138.   (APTR *)&DiskfontBase, "diskfont.library",   36,0,
  139.   (APTR *)&GadToolsBase, "gadtools.library",   36,0,
  140.   (APTR *)&GfxBase,      "graphics.library",   36,0,
  141.   (APTR *)&IconBase,     "icon.library",       36,0,
  142.   (APTR *)&IFFParseBase, "iffparse.library",   36,0,
  143.   (APTR *)&IntuitionBase,"intuition.library",  36,0,
  144.   (APTR *)&UtilityBase,  "utility.library",    36,0,
  145.   0,0,0
  146. };
  147.  
  148. ULONG ListToCyc[]={1,0,2,3};
  149. WORD  CurrentList_2=0,
  150.       CurrentList=1;
  151.  
  152. struct NewMenu *FindNM(struct NewMenu *Array, APTR UserData);
  153.  
  154.  
  155. void SetMPSem(void);
  156.  
  157. void PrintPStrings(void);
  158.  
  159. void main(int argc, char **argv)
  160. {
  161.   ULONG l;
  162.   struct Screen *ps;
  163.   LONG gotsem=0;
  164.  
  165.  
  166.  
  167.   if(LocaleBase=OpenLibrary("locale.library",38))
  168.     Catalog=OpenCatalog(NULL,(STRPTR)"modeproprefs.catalog", TAG_DONE);
  169.   else
  170.     Catalog=NULL;
  171.   
  172.   InitStrings();
  173.   //NewList(&ForcedEditList);
  174.   ForcedEditMsg=0;
  175.  
  176.   if(ex_OpenLibs(argc,//                                                                               (4.63.1) (09/17/00)//  (4.64.1) (09/17/00)
  177.               "ModeProPrefs",
  178.               GetString(MSG_REQ_COULDNT_OPEN_LIBS),
  179.               GetString(MSG_REQ_NAME_VER_FMT),
  180.               GetString(MSG_REQ_OK),
  181.               MP_Libs))
  182.   {
  183.     
  184. //      PrintPStrings();
  185.     
  186.     if(ps=LockPubScreen(NULL))
  187.     {
  188.       if(DrawInfo=GetScreenDrawInfo(ps))
  189.       {
  190.         for(l=0;l<DrawInfo->dri_NumPens && l<NumDriPens;l++)
  191.           defaultpens[l]=DrawInfo->dri_Pens[l];      
  192.         FreeScreenDrawInfo(ps,DrawInfo);
  193.       }
  194.       UnlockPubScreen(NULL,ps);
  195.     }
  196.  
  197.     if(GetArgs(argc,argv))
  198.     {
  199. //      printf("Got Args\n");
  200.       
  201. //        printf("Got Scr\n");
  202.         Forbid();
  203.         MPSem=(struct MPSem *)FindSemaphore((UBYTE *)"ModePro");
  204.         if(MPSem)
  205.           gotsem=AttemptSemaphoreShared(&MPSem->SharedSem);
  206.         Permit();
  207.         
  208.         if(!gotsem)
  209.         {
  210.           EZReq(0,0,ModePro,GetString(MSG_ERR_NOPATCH),GetString(MSG_REQ_OK),0);
  211.         }
  212.         else
  213.         {
  214. //          printf("Got Sem\n");
  215. //        SetMPSem();//                                                                                (4.62.9)
  216.           if(AttemptSemaphore(&MPSem->PrefsSem))
  217.           {
  218. //            printf("Got P Args\n");
  219.             if(MPSem->Version==SemVersion && MPSem->Revision==SemRevision)
  220.             {
  221. //              printf("Got Vers\n");
  222.               SetMPSem();//                                                                            (4.62.10)
  223.  
  224.               if(ArgFrom)
  225.               {
  226.                 //printf("ArgFrom = %s\n",ArgFrom);
  227.                 ObtainSemaphore(&MPSem->ListSem);
  228.                 ObtainSemaphore(&MPSem->NodeSem);
  229.                 FreeAllDefLists(MPSem->PromotionList);
  230.                 PrefLoadFile(ArgFrom);
  231.                 ReleaseSemaphore(&MPSem->NodeSem);
  232.                 ReleaseSemaphore(&MPSem->ListSem);
  233.               }
  234.               
  235.               if(Arg_Import)
  236.               {
  237.                 ObtainSemaphore(&MPSem->ListSem);
  238.                 ImportFile(Arg_Import);
  239.                 ReleaseSemaphore(&MPSem->ListSem);
  240.               }
  241.               
  242.               if(ArgEdit)
  243.               {
  244.                 if(ReplyPort=CreateMsgPort())
  245.                 {
  246.                   //printf("Got RPort\n");
  247.                   if(PrefsPort=CreateMsgPort())
  248.                   {
  249.                     if((ForcedSig=AllocSignal(-1))!=-1)
  250.                     {
  251.                       //printf("Got PPort\n");
  252.                       ObtainSemaphore(&MPSem->PortSem);
  253.                       MPSem->PrefsPort=PrefsPort;
  254.                       MPSem->PrefsToDoPort.mp_SigBit  =ForcedSig;//                                    (4.62.3)
  255.                       MPSem->PrefsToDoPort.mp_SigTask =FindTask(0);//                                  (4.62.3)
  256.                       MPSem->PrefsToDoPort.mp_Flags   =PA_SIGNAL;//                                    (4.62.3)
  257.                       
  258.                       ForcedEditMsg=(struct MPMessage *)GetMsg(&MPSem->PrefsToDoPort);//               (4.62.4)
  259.                       
  260.                       ReleaseSemaphore(&MPSem->PortSem);
  261.                       StrHook.h_Entry             =(HOOKFUNC)ExcludeHook;
  262.                       PenLVHook.h_Entry           =(HOOKFUNC)PensLVFunc;
  263.                       StrCursorHook.h_Entry       =(HOOKFUNC)PenValFunc;
  264.                       PromotionLVHook.h_Entry     =(HOOKFUNC)PromotionLVFunc;
  265.                       //MainWinHook.h_Entry=WinBackFillHook;
  266.                       //PaletteWinHook.h_Entry=WinBackFillHook;
  267.                  
  268.                       NumDriPens=9;
  269.                       V39=FALSE;
  270.                   
  271.                       if(((struct Library *)IntuitionBase)->lib_Version>38)
  272.                       {
  273.                         NumDriPens=12;
  274.                         V39=TRUE;
  275.                       }
  276.                       
  277.                       if(WinAdd=WindowName=AllocVec(strlen(MPSem->HotKey)+
  278.                                                     strlen(GetString(MSG_WINDOW_TITLE))+
  279.                                                     strlen(Title1)+
  280.                                                     strlen(Title2)+1,MEMF_CLEAR|MEMF_PUBLIC))
  281.                       {
  282.                         strcpy(WindowName,GetString(MSG_WINDOW_TITLE));
  283.                         strcat(WindowName,Title1);
  284.                         strcat(WindowName,MPSem->HotKey);
  285.                         strcat(WindowName,Title2);
  286.                       }
  287.                       else
  288.                       {
  289.                         WindowName=ModePro; 
  290.                       }
  291.                         
  292. //                    printf("Got WinName\n");
  293.                       SetupPenNodes();
  294. //            printf("Got PenNodes\n");
  295.         
  296.                       ObtainSemaphoreShared(&MPSem->ListSem);
  297.                       FixScreenModeNames();
  298.                       
  299. //                    printf("Got ModeNames\n");
  300.                       if(GadgetInit())
  301.                       {
  302.                         if(ShowGUI())
  303.                         {
  304.                           struct Process *proc;
  305.                           struct Window *winptr;
  306.     
  307. //                            printf("Got GUI\n");
  308.                           proc=(struct Process *)FindTask(0);
  309.                           winptr=proc->pr_WindowPtr;
  310.                           proc->pr_WindowPtr=Win;
  311.                  
  312.                           ProcessInput();
  313.                           
  314. //                        DKP("main() 119\n");
  315.                           proc->pr_WindowPtr=winptr;
  316. //                        DKP("main() 120\n");
  317.                           HideGUI();
  318.                         }
  319.                         GadgetCleanup();
  320.                       }
  321. //                    DKP("main() 200\n");
  322.                       ReleaseSemaphore(&MPSem->ListSem);
  323. //                    DKP("main() 201\n");                     
  324.                       FreeVec(WinAdd);
  325. //                    DKP("main() 202\n");             
  326.                       ObtainSemaphore(&MPSem->PortSem);
  327. //                    DKP("main() 203\n");
  328.                       MPSem->PrefsPort=0;
  329.                       
  330.                       MPSem->PrefsToDoPort.mp_SigBit  =255;//                                          (4.62.5)
  331.                       MPSem->PrefsToDoPort.mp_SigTask =0;//                                            (4.62.5)
  332.                       MPSem->PrefsToDoPort.mp_Flags   =PA_IGNORE;//                                    (4.62.5)
  333.                       {
  334.                         struct Message *msg;
  335.                         while(msg=GetMsg(PrefsPort))
  336.                           ReplyMsg(msg);
  337.                         
  338.                         if(ForcedEditMsg)
  339.                           ReplyMsg((struct Message *)ForcedEditMsg);
  340.                       
  341.                         while(msg=GetMsg(&MPSem->PrefsToDoPort))//                                     (4.62.6)
  342.                           ReplyMsg(msg);
  343.                       
  344.                       }
  345. //                    DKP("main() 204\n");
  346.                       ReleaseSemaphore(&MPSem->PortSem);
  347.                       FreeSignal(ForcedSig);
  348.                     }
  349. //                  DKP("main() 205\n");
  350.                     DeleteMsgPort(PrefsPort);
  351. //                  DKP("main() 206\n");                    
  352.                   }// endif CreateMsgPort(PrefsPort)
  353.                   DeleteMsgPort(ReplyPort);
  354. //                  DKP("main() 207\n");
  355.                 }// if CreateMsgPort(ReplyPort)
  356.               }// endif(ArgEdit)
  357.               else
  358.                 if(ArgSave)
  359.                 {
  360.                   ObtainSemaphore(&MPSem->ListSem);
  361.                   ObtainSemaphore(&MPSem->NodeSem);
  362.                   PrefSaveFile(EnvArcFile);
  363.                   PrefSaveFile(EnvFile);
  364.                   ReleaseSemaphore(&MPSem->NodeSem);            
  365.                   ReleaseSemaphore(&MPSem->ListSem);
  366.                 }
  367.             }
  368.             else
  369.               EZReq(0,0,ModePro,GetString(MSG_ERR_WRONGVERSIONS),MiscText[OK],
  370.                                          MPSem->Version,MPSem->Revision,SemVersion,SemRevision);          
  371.             ReleaseSemaphore(&MPSem->PrefsSem);
  372.           }//if(attemptsemshared()        
  373.           ReleaseSemaphore(&MPSem->SharedSem);//                                                        (4.61.3)
  374.         }//endelse (gotsem)
  375.       CleanupArgs();
  376.     }
  377.     ex_CloseLibs(MP_Libs);//                                                                           (4.64.2) (09/17/00)
  378.   } 
  379.   if(LocaleBase)
  380.   {
  381.     CloseCatalog(Catalog);
  382.     CloseLibrary(LocaleBase);
  383.   }
  384. }
  385.  
  386. void SetMPSem(void)
  387. {
  388.   if(Arg_Promo!=5)
  389.   {
  390.     MPSem->Enabled=Arg_Promo;
  391.   }
  392.     
  393.   if(Arg_NLM!=5)
  394.   {
  395.     MPSem->EnabledNLM=Arg_NLM;
  396.   }
  397.     
  398.   if(Arg_Ask!=5)
  399.   {
  400.     MPSem->CatchScreens=Arg_Ask;
  401.   }
  402.     
  403.   if(Arg_CH!=5)
  404.   {
  405.     MPSem->CenterAll=(MPSem->CenterAll & ~1) | ( Arg_CH ? 1 : 0);
  406.   }
  407.   
  408.   if(Arg_CV!=5)
  409.   {
  410.     MPSem->CenterAll=(MPSem->CenterAll & ~2) | ( Arg_CV ? 2 : 0);
  411.   }
  412.    
  413.   if(Arg_Debug!=5)
  414.   {
  415.     MPSem->Debug=Arg_Debug;
  416.   }
  417. }
  418.  
  419.  
  420.  
  421. struct TextFont *GUIFont=0;
  422.  
  423. BOOL RemakeGads(void)
  424. {
  425.   FreeMPPGadgets();
  426.   if(MakeMPPGadgets(Win,VI,TAttr))
  427.   {
  428.     WORD x1,x2,y1,y2;
  429.               
  430.     x1=Win->BorderLeft;
  431.     x2=Win->Width-Win->BorderRight-1;
  432.     y1=Win->BorderTop;
  433.     y2=Win->Height-Win->BorderBottom-1;
  434.     if(x1<=x2 && y1<=y2)
  435.       EraseRect(Win->RPort,x1,y1,x2,y2);
  436.     
  437.     LG_AddGadgets(Win,GadControl);
  438.     UpdateGadgets();
  439.     RefreshGUI();
  440.     RefreshWindowFrame(Win);
  441.     return(1);
  442.   }
  443.   return(0);
  444. }
  445.  
  446. extern WORD WindowWidth,WindowHeight;  
  447.  
  448. BOOL ShowGUI(void)
  449. {
  450.   WORD zoom[4];
  451.  
  452.   if(Scr=GetScreen())
  453.   {
  454.     if(VI=GetVisualInfo(Scr,TAG_END))
  455.     {
  456.       zoom[2]=160;
  457.       zoom[3]=Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  458.       if(V39)
  459.       {
  460.         zoom[0]=zoom[1]=~0;
  461.       }
  462.       else
  463.       {
  464.         zoom[0]=0;
  465.         zoom[1]=zoom[3];
  466.       }
  467.       
  468.       if(MPSem->FirstPrefsOpen)
  469.       {
  470.         MPSem->TopEdge  =Scr->BarHeight+1;
  471.         MPSem->LeftEdge =0;
  472.         MPSem->FirstPrefsOpen=0;
  473.         MPSem->WinWidth=(WORD)(WindowWidth  * XScale);
  474.         MPSem->WinHeight=(WORD)(WindowHeight  * YScale);
  475.       }
  476.       else
  477.       {
  478.         LVActive    =MPSem->LVActive;
  479.         CurrentList =MPSem->CurrentList;
  480.  
  481.         // 4.53
  482.         MPSem->WinWidth   =max(MPSem->WinWidth ,(WORD)(WindowWidth  * XScale));
  483.         MPSem->WinHeight  =max(MPSem->WinHeight,(WORD)(WindowHeight * YScale));
  484.  
  485. //        MPSem->WinWidth   =max(MPSem->WinWidth ,(WORD)(WindowWidth));
  486. //        MPSem->WinHeight  =max(MPSem->WinHeight,(WORD)(WindowHeight));
  487.  
  488.       }
  489.        if(Win=OpenWindowTags(NULL, 
  490.                           WA_MaxWidth         ,~0,
  491.                           WA_MaxHeight        ,~0,
  492.                           
  493.                           TAG_SKIP            ,(MyScreen?13:0),
  494.                           //WA_MinHeight        ,(LONG)(WindowHeight * YScale + Scr->WBorTop  + Scr->RastPort.TxHeight + 1 + Scr->WBorBottom) ,
  495.                           WA_MinHeight        ,(LONG)(WindowHeight + Scr->WBorTop  + Scr->RastPort.TxHeight + 1 + Scr->WBorBottom) ,
  496.                           WA_InnerWidth       ,MPSem->WinWidth,
  497.                           WA_InnerHeight      ,MPSem->WinHeight,
  498.                           WA_Left             ,MPSem->LeftEdge,
  499.                           WA_Top              ,MPSem->TopEdge,
  500.                           WA_DragBar          ,TRUE,
  501.                           WA_DepthGadget      ,TRUE,
  502.                           WA_Zoom             ,zoom,
  503.                           WA_Title            ,WindowName ,
  504.                           WA_SizeGadget       ,1,
  505.                           WA_SizeBBottom      ,1,
  506.                           TAG_SKIP            ,6,
  507.                           
  508.                           WA_InnerWidth       ,(LONG)(WindowWidth  * XScale),
  509.                           WA_InnerHeight      ,(LONG)(WindowHeight  * YScale),
  510.                           WA_Backdrop         ,MyScreen,
  511.                           WA_Borderless       ,TRUE,
  512.                           WA_Left             ,0,
  513.                           WA_Top              ,Scr->BarHeight+1,
  514.                           
  515.                           WA_NewLookMenus     ,TRUE,
  516.                           WA_AutoAdjust       ,TRUE,
  517.                           WA_Activate         ,TRUE,
  518.                           WA_SimpleRefresh    ,TRUE,
  519.                           WA_IDCMP            ,MPP_IDCMP | IDCMP_NEWSIZE,
  520.                           WA_PubScreen        ,Scr,//                                                  (4.56.1)
  521.                           TAG_DONE  ))//    TAG_DONE was missing                                       (4.56.1)
  522.       {
  523. // 4.53
  524.         Win->MinWidth =(WORD)(WindowWidth  * XScale + Win->BorderLeft + Win->BorderRight);
  525.         Win->MinHeight=(WORD)(WindowHeight * YScale + Win->BorderTop  + Win->BorderBottom);
  526. //        Win->MinWidth =(WORD)(WindowWidth  + Win->BorderLeft + Win->BorderRight);
  527. //        Win->MinHeight=(WORD)(WindowHeight + Win->BorderTop  + Win->BorderBottom);
  528.         SetFont(Win->RPort,GUIFont);
  529.         FindMaxPenNameSize(TAttr);
  530.         if(MakeMPPGadgets(Win,VI,TAttr))
  531.         {
  532.           LG_AddGadgets(Win,GadControl);
  533.           GT_RefreshWindow(Win,0);
  534.           //DrawBevelBoxes(Win,VI,BBox,BevelBoxes,XScale,YScale);
  535.           RefreshGUI();
  536.            {
  537.             struct NewMenu *menu;
  538.             
  539.             if(menu=FindNM(nm,(APTR)M_ENABLENL))
  540.             {
  541.               if(!V39)
  542.                 menu->nm_Flags =((menu->nm_Flags | NM_ITEMDISABLED) & ~CHECKED);
  543.             }
  544.           }
  545.            if((MenuStrip=CreateMenus(nm,TAG_END))!=NULL)
  546.           {
  547.             if((LayoutMenus(MenuStrip,VI,
  548.                             GTMN_NewLookMenus,TRUE,
  549.                             TAG_END))!=NULL)
  550.             {          
  551.               if((SetMenuStrip(Win,MenuStrip))!=NULL)
  552.               {
  553.                 //LVActive=0;
  554.                  GT_RefreshWindow(Win,NULL);
  555.                 RefreshMenus();
  556.                 UpdateGadgets();
  557.                 ScreenToFront(Scr);
  558.                 return(TRUE);
  559.               }
  560.             }
  561.           }
  562.         }
  563.       }
  564.     }
  565.   }
  566.   HideGUI();
  567.   return(FALSE);
  568. }
  569.  
  570.  
  571. void HideGUI()
  572. {
  573.   DKP("HideGUI()\n");
  574.   CleanUp();
  575.   if(Win)           
  576.   { 
  577.     MPSem->CurrentList=CurrentList;
  578.     MPSem->LVActive   =LVActive;
  579.   DKP("HideGUI() 1\n");
  580.     ClearMenuStrip(Win);
  581.   DKP("HideGUI() 2\n");
  582.     MPSem->LeftEdge=Win->LeftEdge;
  583.     MPSem->TopEdge=Win->TopEdge;
  584.     MPSem->WinWidth=GetWinInnerWidth(Win);
  585.     MPSem->WinHeight=GetWinInnerHeight(Win);
  586.   DKP("HideGUI() 3\n");
  587.     FreeMPPGadgets();
  588.   DKP("HideGUI() 5\n");
  589.     CloseWindow(Win);    
  590.   DKP("HideGUI() 6\n");
  591.     
  592.     Win=0;
  593.   }
  594.     DKP("HideGUI() 7\n");       
  595.   FreeMenus(MenuStrip);       MenuStrip=0;
  596.     DKP("HideGUI() 8\n");
  597.   FreeVisualInfo(VI);         VI=0;
  598.     DKP("HideGUI() 9\n");
  599.   
  600.   DKP("HideGUI() 10\n");
  601.   if(GUIFont) CloseFont(GUIFont);
  602.     DKP("HideGUI() 11\n");
  603.   
  604.   
  605.   
  606.   ReleaseScreen(Scr);
  607.   /* These functions I KNOW are safe to call with a NULL */
  608.  
  609. }
  610.  
  611. struct TextAttr *WhichFont(struct Screen *Scr, struct TextAttr *TA, ... );
  612.  
  613. struct TextAttr *WhichFont(struct Screen *Scr, struct TextAttr *TA, ... )
  614. {
  615.   struct TextAttr **ta;
  616.   
  617.   ta=&TA;
  618.   
  619.   while(*ta)
  620.   {
  621.     if(GUIFont=OpenDiskFont(*ta))
  622.     {
  623.       // 4.53
  624.       GetGUIScale(*ta,GText,&PXScale,&PYScale);
  625.       XScale=PXScale;
  626.       YScale=PYScale;
  627.       if(CheckInnerWindowSize(Scr,WindowWidth,WindowHeight,XScale,YScale))
  628.       {
  629.         return(*ta);
  630.       }
  631.       CloseFont(GUIFont);
  632.       GUIFont=0;
  633.     }
  634.     ta++;
  635.   }
  636.   return(0);
  637. }
  638.  
  639. struct Screen *GetScreen(void)
  640. {
  641.   struct Screen *gs;
  642.   WORD pens[]={~0};
  643.   ULONG dispid;
  644.   struct TextAttr *ta;
  645.   BOOL cps,cs;
  646.   
  647.   MyScreen=FALSE;
  648.   
  649.   cps=MPSem->CatchPubScreens;
  650.   cs =MPSem->CatchScreens;
  651.   
  652.   MPSem->CatchPubScreens=0;
  653.   MPSem->CatchScreens=0;
  654.   
  655.   if(gs=LockPubScreen(ArgPubscreen))
  656.   {
  657.     SysFont=*gs->Font;
  658.     
  659.     if(UserFontName)
  660.     {
  661.       User.ta_Name  =UserFontName;
  662.       User.ta_YSize =UserFontSize;
  663.       User.ta_Style =0;
  664.       User.ta_Flags =0;
  665.       ta=&User;
  666.     }
  667.     else
  668.       ta=&SysFont;
  669.  
  670.     /* Pick which font works with the PubScreen gs */
  671.     if(!(TAttr=WhichFont(gs,ta,&SysFont,&Topaz8,0)))
  672.     { /* If no fonts fits the screen */
  673. //      TAttr=ta;
  674.       TAttr=&Topaz8;
  675.       dispid=GetVPModeID(&(gs->ViewPort));//                                                         (4.63.1)//  (4.63.3)
  676.       UnlockPubScreen(0,gs);//                                                                       (4.63.1)//  (4.63.2)
  677.       gs=0;      //                                                                                  (4.63.1)//  (4.63.2)
  678.       
  679.       if(GUIFont=OpenDiskFont(TAttr))
  680.       {
  681.         GetGUIScale(TAttr,GText,&XScale,&YScale);//                                                    (4.63.1)
  682.         printf("%f %f\n",XScale,YScale);
  683.         MyScreen=TRUE;
  684.         gs=OpenScreenTags(0, SA_LikeWorkbench, TRUE,
  685.                              SA_Title        , ModePro,
  686.                              SA_DisplayID    , dispid,
  687.                              SA_Overscan     , OSCAN_TEXT,
  688.                              SA_AutoScroll   , TRUE,
  689.                              SA_Font         , TAttr,
  690.                              SA_Width        , (LONG)(WindowWidth  * XScale),
  691.                              SA_Height       , (LONG)(WindowHeight * YScale + TAttr->ta_YSize + 3),
  692.                              SA_Depth        , (V39?3:2), // Open a 8 color screen if V39 (for backdrop requester)
  693.                              SA_SharePens    ,1,          // Sharepens for backdrop requester
  694.                              SA_Pens         , pens,
  695.                              TAG_DONE);
  696.       }
  697.     }
  698.   }
  699.   if(gs)
  700.   {
  701.     if(DrawInfo=GetScreenDrawInfo(gs))
  702.     {
  703.       if(V39)
  704.       {
  705.         struct ColorMap *cmap;
  706.         struct RGB fill,pen;
  707. //        LONG diff;
  708.  
  709.         cmap=gs->ViewPort.ColorMap;
  710.  
  711. #define FSHINE_PERCENT (float)6/10
  712. #define FSHADOW_PERCENT (float)4/10
  713.  
  714.         GetRGB32(cmap,DrawInfo->dri_Pens[FILLPEN],      1,(ULONG *)&fill);        
  715.         
  716. //        GetRGB32(cmap,DrawInfo->dri_Pens[SHINEPEN],     1,(ULONG *)&pen);
  717.         pen.Red=pen.Green=pen.Blue=0xffffffff;
  718.         FillShinePen=ObtainBestPen(cmap,
  719.                     (ULONG)(fill.Red   - ((float)fill.Red   - pen.Red)      *FSHINE_PERCENT),
  720.                     (ULONG)(fill.Green - ((float)fill.Green - pen.Green)    *FSHINE_PERCENT),
  721.                     (ULONG)(fill.Blue  - ((float)fill.Blue  - pen.Blue)     *FSHINE_PERCENT),
  722.                     0);
  723.  
  724. //        GetRGB32(cmap,DrawInfo->dri_Pens[SHADOWPEN],     1,(ULONG *)&pen);
  725.         pen.Red=pen.Green=pen.Blue=0;
  726.         FillShadowPen=ObtainBestPen(cmap,
  727.                     (ULONG)(fill.Red   - ((float)fill.Red   - pen.Red)      *FSHADOW_PERCENT),
  728.                     (ULONG)(fill.Green - ((float)fill.Green - pen.Green)    *FSHADOW_PERCENT),
  729.                     (ULONG)(fill.Blue  - ((float)fill.Blue  - pen.Blue)     *FSHADOW_PERCENT),
  730.                     0);
  731.  
  732.         BackdropPen=ObtainPen(gs->ViewPort.ColorMap,-1,0,0,0,PEN_EXCLUSIVE);
  733.  
  734.       
  735.       }
  736.     //  MainWinHook.h_Data=DrawInfo->dri_Pens[BACKGROUNDPEN];
  737.     }
  738.   }
  739.   else
  740.   {
  741.     if(GUIFont)
  742.       CloseFont(GUIFont);
  743.   }
  744.   
  745.   MPSem->CatchPubScreens=cps;
  746.   MPSem->CatchScreens=cs;
  747.   
  748.   return(gs);
  749. }
  750.  
  751. void ReleaseScreen(struct Screen *S)
  752. {
  753.   if(S)
  754.   {
  755.     if(V39)
  756.     {
  757.       ReleasePen(S->ViewPort.ColorMap,BackdropPen);
  758.       ReleasePen(S->ViewPort.ColorMap,FillShinePen);
  759.       ReleasePen(S->ViewPort.ColorMap,FillShadowPen);
  760.     }
  761.     
  762.     FreeScreenDrawInfo(S,DrawInfo);
  763.     if(MyScreen)
  764.       CloseScreen(S);
  765.     else
  766.       UnlockPubScreen(0,S);
  767.   }
  768.   if(GUIFont)
  769.     CloseFont(GUIFont);
  770. }
  771.  
  772. void CleanUp(void)
  773. {
  774.   FreeAslRequest(ScrReq);
  775.   FreeAslRequest(FileReq);
  776.   FreeAslRequest(PalFileReq);
  777.   FreeAslRequest(FontReq);
  778.   FreeAslRequest(BackdropFileReq);
  779.   PR_FreePaletteRequest(BackdropPReq);
  780.   PR_FreePaletteRequest(PalettePReq);
  781. }
  782.  
  783.  
  784.  
  785.  
  786.